package com.database.bean;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="AGENTTYPE")
@AttributeOverride( name="id", column = @Column(name="id") )
@XmlRootElement
public class AgentType extends BaseBean{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Column(name="agentName")
	private String agentName;
	
	@Column(name="moneyPerPeriod")
	private Integer moneyPerPeriod;
	
	@Min(0)
	@Column(name="amount")
	private Integer amount;
	
	@Min(0)
	@Max(1)
	@Column(name="meanQuality")
	private Double meanQuality;
	
	@Min(0)
	@Max(1)
	@Column(name="meanPrice")
	private Double meanPrice;
	
	@Min(0)
	@Max(1)
	@Column(name="meanImage")
	private Double meanImage;
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="roundId")
	private Round round=null;
	
	@OneToMany(fetch = FetchType.EAGER, cascade={CascadeType.ALL})
	@Fetch(value = FetchMode.JOIN)
    @JoinColumn(name="agenttype_id")
	private List<AgentTypeCompanyProduct>agentTypeCompanyProducts = new ArrayList<AgentTypeCompanyProduct>();
	
	
	@OneToMany(fetch = FetchType.LAZY, cascade={CascadeType.ALL})
	@Fetch(value = FetchMode.SUBSELECT)
    @JoinColumn(name="agenttype_id")
	private List<Agent>agents =new ArrayList<Agent>();

	/**
	 * 
	 */
	public AgentType() {
		super();
	}
	

	public AgentType(String agentName, Integer moneyPerPeriod, Integer amount,Double meanQuality, Double meanPrice, Double meanImage) {
		super();
		this.agentName = agentName;
		this.moneyPerPeriod = moneyPerPeriod;
		this.amount = amount;
		this.meanQuality = meanQuality;
		this.meanPrice = meanPrice;
		this.meanImage = meanImage;
	}




	public String getAgentName() {
		return agentName;
	}


	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	public Integer getMoneyPerPeriod() {
		return moneyPerPeriod;
	}


	public void setMoneyPerPeriod(Integer moneyPerPeriod) {
		this.moneyPerPeriod = moneyPerPeriod;
	}


	public Integer getAmount() {
		return amount;
	}


	public void setAmount(Integer amount) {
		this.amount = amount;
	}


	public Double getMeanQuality() {
		return meanQuality;
	}


	public void setMeanQuality(Double meanQuality) {
		this.meanQuality = meanQuality;
	}


	public Double getMeanPrice() {
		return meanPrice;
	}


	public void setMeanPrice(Double meanPrice) {
		this.meanPrice = meanPrice;
	}


	public Double getMeanImage() {
		return meanImage;
	}


	public void setMeanImage(Double meanImage) {
		this.meanImage = meanImage;
	}


	@Override
	public String toString() {
		return "AgentType [agentName=" + agentName + ", moneyPerPeriod="
				+ moneyPerPeriod + ", amount=" + amount + ", meanQuality="
				+ meanQuality + ", meanPrice=" + meanPrice + ", meanImage="
				+ meanImage + "]";
	}


	public Round getRound() {
		return round;
	}


	public void setRound(Round round) {
		this.round = round;
	}


	/**
	 * @return the agentTypeCompanyProducts
	 */
	public List<AgentTypeCompanyProduct> getAgentTypeCompanyProducts() {
		return agentTypeCompanyProducts;
	}


	/**
	 * @param agentTypeCompanyProducts the agentTypeCompanyProducts to set
	 */
	public void setAgentTypeCompanyProducts(
			List<AgentTypeCompanyProduct> agentTypeCompanyProducts) {
		this.agentTypeCompanyProducts = agentTypeCompanyProducts;
	}


	public List<Agent> getAgents() {
		return agents;
	}


	public void setAgents(List<Agent> agents) {
		this.agents = agents;
	}
	
	
	public void addAgentTypeCompanyProduct(AgentTypeCompanyProduct atcp){
		if(this.agentTypeCompanyProducts==null)
			this.agentTypeCompanyProducts=new ArrayList<AgentTypeCompanyProduct>();
		
		this.agentTypeCompanyProducts.add(atcp);
	}
	
	
}
